Visualization with HoloViz


Imports

import uxarray as ux
import holoviews as hv
import numpy as np
import warnings
import matplotlib
import matplotlib.pyplot as plt
import hvplot.pandas

# Create blue colormap for plotting
cmap = matplotlib.colors.LinearSegmentedColormap.from_list("Color_Theme", plt.cm.Blues(np.linspace(0.2, 1, 30)))

warnings.filterwarnings("ignore")
ds_file_480 = "../meshfiles/oQU480.230422.nc"
ds_file_120 = "../meshfiles/oQU120.230424.nc"

uxds_480 = ux.open_dataset(ds_file_480, ds_file_480)
uxds_120 = ux.open_dataset(ds_file_120, ds_file_120)

Visualizing Grid Geometry

gdf_480_grid = uxds_480.uxgrid.to_geodataframe()
gdf_120_grid = uxds_120.uxgrid.to_geodataframe()

Nodes

hv.extension("matplotlib")

plot_kwargs = {"size": 5.0, "xlabel": "Longitude", "ylabel": "Latitude", "xlim": (-110, -50), "ylim": (0, 40),
               "coastline": True, "width": 800}
hv.Layout(gdf_480_grid.hvplot.points(**plot_kwargs) + gdf_120_grid.hvplot.points(**plot_kwargs)).opts(fig_size=300).cols(1)
hv.extension("bokeh")

plot_kwargs = {"s": 4.0, "xlabel": "Longitude", "ylabel": "Latitude", "xlim": (-110, -50), "ylim": (0, 40),
               "coastline": True}
hv.Layout(gdf_480_grid.hvplot.points(**plot_kwargs) + gdf_120_grid.hvplot.points(**plot_kwargs)).cols(1)

Edges

hv.extension("matplotlib")

plot_kwargs = {"linewidth": 0.5, "xlabel":" Longitude", "ylabel": "Latitude", "xlim": (-110, -50), "ylim": (0, 40),
               "coastline": True, "width": 1600}
hv.Layout(gdf_480_grid.hvplot.paths(**plot_kwargs) + gdf_120_grid.hvplot.paths(**plot_kwargs)).opts(fig_size=300).cols(1)
hv.extension("bokeh")

plot_kwargs = {"line_width": 0.5, "xlabel": "Longitude", "ylabel": "Latitude", "xlim": (-110, -50), "ylim": (0, 40),
               "coastline": True}
hv.Layout(gdf_480_grid.hvplot.paths(**plot_kwargs) + gdf_120_grid.hvplot.paths(**plot_kwargs)).cols(1)

Visualizing Grid Geometry with Data

gdf_480_grid_data = uxds_480['bottomDepth'].to_geodataframe()
gdf_120_grid_data = uxds_120['bottomDepth'].to_geodataframe()
hv.extension("matplotlib")

plot_kwargs = {"c": "bottomDepth", "cmap": cmap} #TODO
# TODO: raster
hv.Layout(gdf_480_grid_data.hvplot.polygons(**plot_kwargs, rasterize=True) +
          gdf_120_grid_data.hvplot.polygons(**plot_kwargs, rasterize=True)).opts(fig_size=100).cols(1)
hv.extension("bokeh")

plot_kwargs = {"c": "bottomDepth",  "cmap": cmap, "line_width": 0.1} #TODO
# TODO: vector
hv.Layout(gdf_480_grid_data.hvplot.polygons(**plot_kwargs, rasterize=False) +
          gdf_120_grid_data.hvplot.polygons(**plot_kwargs, rasterize=False)).cols(1)
# TODO: raster
hv.Layout(gdf_480_grid_data.hvplot.polygons(**plot_kwargs, rasterize=True) +
          gdf_120_grid_data.hvplot.polygons(**plot_kwargs, rasterize=True)).cols(1)